package com.le.tester.imooc.masterJUC.threadlocal;

import com.le.tester.common.Const;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 描述：1000个任务需要执行，使用线程池来创建线程
 */
public class ThreadLocalNormalUsage02 {

    public static final ExecutorService threadPool = Executors.newFixedThreadPool(10);

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            int finalI = i;
            threadPool.submit(new Runnable() {
                @Override
                public void run() {
                    String date = new ThreadLocalNormalUsage02().date(finalI);
                    System.out.println("threadPool string date:" + date);
                }
            });
        }
        //就像锁一样，还是得关闭线程池
        threadPool.shutdown();
    }

    public String date(int seconds) {
        //字符串日期格式转换,参数的单位是毫秒，从1970.01.01 00:00:00 GTM开始计时
        Date date = new Date(1000 * seconds);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Const.STANDARD_FORMAT);
        return simpleDateFormat.format(date);
    }
}
